<?php
defined('OA_LIB_PATH') || define('OA_LIB_PATH', '/opt/op/OALib');
defined('OPEN_LIB_PATH') || define('OPEN_LIB_PATH', '/opt/op/OpenLib');

require_once 'PHPUnit/Framework.php';
require_once 'Log.php';
require_once OPEN_LIB_PATH . '/open/models/OaAppModel.php';
require_once OPEN_LIB_PATH . '/open/models/OaAppServerModel.php';
$test1 = new OaAppServerModelTest();
$test1->testAddLoginServer();

class OaAppServerModelTest extends PHPUnit_Framework_TestCase
{
    private $_logger;
    private $_model;
    
    protected function setUp()
    {
        $logger = Log::factory('console', '', '', array(
    		'lineFormat' => '[%1$s] [%3$s] %5$s(%6$s): %4$s',
    		'timeFormat' => '%Y-%m-%d %H:%M:%S'
        ), PEAR_LOG_INFO);
        $this->_logger = $logger;
        $this->_model = new OaAppServerModel(OaAppModel::APP_CONFIG_ENV_PRODUCTION, $logger);
    }
    
    protected function tearDown()
    {
        
    }
    
    public function __construct()
    {
    	parent::__construct();
    	$this->setUp();
    }
    public function testAddArea()
    {
    	$this->markTestSkipped();
    	$result = $this->_model->addArea(110091800, '98区', 1, array(
    		'area_code' => 98,
    		'not_exist' => 'not exist'
    	));
    	$this->_logger->info($result);
    	$this->_logger->info($this->_model->getErrorMessage());
    	$this->assertTrue($result !== false);
    }
    
    public function testSearchArea()
    {
    	$this->markTestSkipped();
    	$result = $this->_model->searchAreas(110091800, '区');
    	$this->_logger->info($result);
    	$this->assertTrue($result !== false);
    }
    
    public function testSearchGroup()
    {
    	$this->markTestSkipped();
    	$result = $this->_model->searchGroups(110091800, '组');
    	$this->_logger->info($result);
    	$this->assertTrue($result !== false);
    }
    
    public function testSearchServer()
    {
    	$this->markTestSkipped();
    	$result = $this->_model->searchServers(110091800, '10.129', '');
    	$this->_logger->info($result);
    	$this->assertTrue($result !== false);
    }
    
    public function testSearchLoginServer()
    {
    	$this->markTestSkipped();
    	$result = $this->_model->searchLoginServers(110091800, '10.129', '');
    	$this->_logger->info($result);
    	$this->assertTrue($result !== false);
    }
    
    public function testGetLoginServerValidToByAGS()
    {
    	$this->markTestSkipped();
    	$result = $this->_model->getLoginServerValidToByAGS(4397);
    	$this->_logger->info($result);
    	$this->assertTrue($result !== false);
    }
    
    public function testSearchPayServer()
    {
    	$this->markTestSkipped();
    	$result = $this->_model->searchPayServers(110091800, '10.129', '');
    	$this->_logger->info($result);
    	$this->assertTrue($result !== false);
    }
    
    public function testGetPayServerValidToByAGS()
    {
    	$this->markTestSkipped();
    	$result = $this->_model->getPayServerValidToByAGS(4397);
    	$this->_logger->info($result);
    	$this->assertTrue($result !== false);
    }
    
    public function testAddLoginServer()
    {
    	$this->_model->setCurrentConfigEnv(OaAppModel::APP_CONFIG_ENV_TEST);
    	$result = $this->_model->addLoginServer(50, '125.70.253.249', 'defaultalias', OaAppServerModel::IDC_TYPE_TELECOM, array(), true);
    	var_dump($result);
    	echo $this->_model->getErrorNo()."\n";
    	$this->_logger->info($result);
    	$this->assertTrue($result !== false);
    }
    
	public function testAddLoginServerValidTo()
    {
    	$this->markTestSkipped();
    	$this->_model->setCurrentConfigEnv(OaAppModel::APP_CONFIG_ENV_TEST);
    	$result = $this->_model->addLoginServerValidTo(50, '125.70.253.249', 'defaultalias', OaAppServerModel::IDC_TYPE_TELECOM, array(), true);
    	var_dump($result);
    	echo $this->_model->getErrorNo()."\n";
    	$this->_logger->info($result);
    	$this->assertTrue($result !== false);
    }
}
